package com.example.zhangxin.myhuatuob2b.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.example.zhangxin.myhuatuob2b.R;
import com.example.zhangxin.myhuatuob2b.fragment.home.store.MoblieLoginFragment;
import com.example.zhangxin.myhuatuob2b.fragment.home.store.UserNameLoginFragment;

import java.util.ArrayList;

public class LoginActivity extends AppCompatActivity {

    private ImageView imageback;
    private TabLayout log_tablayout;
    private ViewPager log_viewpager;
    private ArrayList<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        initData();
    }

    private void initData() {
        data = new ArrayList<>();
        data.add("账号登录");
        data.add("验证码登录");

        log_viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                Fragment fragment = null;
                switch (position){
                    case 0:
                        fragment = new UserNameLoginFragment();
                        break;
                    case 1:
                        fragment = new MoblieLoginFragment();
                        break;
                }

                return fragment;
            }

            @Override
            public int getCount() {
                return data.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return data.get(position);
            }
        });

        log_tablayout.setupWithViewPager(log_viewpager);
    }

    private void initView() {
        imageback = (ImageView) findViewById(R.id.imageback);
        log_tablayout = (TabLayout) findViewById(R.id.log_tablayout);
        log_viewpager = (ViewPager) findViewById(R.id.log_viewpager);
    }
}
